
# -*-  coding:utf-8 -*- 
# Author : lihongliang

import os


#account = ["alex","abc123",0] # 1 locked,0 active
#u = [alex,alex,jack]


input_users = []

count = 0
while count < 3:
    count += 1
    username = input("Username:").strip()
    password = input("Password:").strip()

    input_users.append(username) # 把这一次输入的用户名 加到列表里
    account_file = "db/%s" % username
    if os.path.isfile(account_file):
        f = open(account_file,'r')
        account = eval(f.read()) #加载账号数据到内存并且把字符串转成列表
        print("--->",type(account),account)
        if username == account[0] and password == account[1]:
            if account[2] == 0: #active
                print("欢迎来到学城！")
                break
            else:
                exit("user %s is locked." % username)
        else:
            print("Wrong username or password. you got %s times to try." % (3-count))

    else:
        print("user does not exist.")

else:
    if input_users.count( input_users[0]) == 3: # 代表3次错误用户名一致，可以锁定
        account[2] = 1 #locked

        f = open("db/%s" % input_users[0],"w")
        f.write(str(account))
        f.close()
        print("user %s got locked." % account[0])



# -*-  coding:utf-8 -*- 
# Author : lihongliang

import os


#account = ["alex","abc123",0] # 1 locked,0 active
#u = [alex,alex,jack]


input_users = []

count = 0
while count < 3:
    count += 1
    username = input("Username:").strip()
    password = input("Password:").strip()

    input_users.append(username) # 把这一次输入的用户名 加到列表里
    account_file = "db/%s" % username
    if os.path.isfile(account_file):
        f = open(account_file,'r')
        account = eval(f.read()) #加载账号数据到内存并且把字符串转成列表
        print("--->",type(account),account)
        if username == account[0] and password == account[1]:
            if account[2] == 0: #active
                print("欢迎来到路飞学城！")
                break
            else:
                exit("user %s is locked." % username)
        else:
            print("Wrong username or password. you got %s times to try." % (3-count))

    else:
        print("user does not exist.")

else:
    if input_users.count( input_users[0]) == 3: # 代表3次错误用户名一致，可以锁定
        account[2] = 1 #locked

        f = open("db/%s" % input_users[0],"w")
        f.write(str(account))
        f.close()
        print("user %s got locked." % account[0])



